package edu.ncsu.csc.itrust.action;

import java.sql.SQLException;
import edu.ncsu.csc.itrust.beans.forms.EditOfficeVisitForm;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.testutils.TestDAOFactory;
import junit.framework.TestCase;

/**
 * Tests Instruction functionality of EditOfficeVisitAction
 * @author Patrick Finegan
 *
 */
public class EditOfficeVisitActionInstructionTest extends TestCase {

	private DAOFactory factory = TestDAOFactory.getTestInstance();
	private TestDataGenerator gen = new TestDataGenerator();
	private EditOfficeVisitAction action;
	
	@Override
	protected void setUp() throws Exception {
		gen.clearAllTables();
		gen.hospitals();
		gen.hcp0();
		gen.patient1();
		gen.admin1();
		gen.officeVisit1();
		gen.ndCodes();
		gen.hw4();
			
		action = new EditOfficeVisitAction(factory, 9000000001L, "1", "1");
	}
	
	public void testInstructionAdd() throws FormValidationException, SQLException{
		EditOfficeVisitForm frm = new EditOfficeVisitForm();
		frm.setHcpID("9000000000");
		frm.setPatientID("1");
		frm.setVisitDate("05/02/2001");
		frm.setAddInstName("Test1");
		frm.setAddInstUrl("http://www.moodle.ncsu.edu");
		frm.setAddInstComment("Test1");
		String temp =  action.updateInformation(frm);
		assertEquals("success", temp);
	}
	
	public void testInstructionRemove() throws FormValidationException, DBException, SQLException{
		//Add an Instruction
		EditOfficeVisitForm frm = new EditOfficeVisitForm();		
		frm.setHcpID("9000000000");
		frm.setPatientID("1");
		frm.setVisitDate("05/02/2001");
		frm.setAddInstName("Test1");
		frm.setAddInstUrl("http://www.moodle.ncsu.edu");
		frm.setAddInstComment("Test1");
		String temp =  action.updateInformation(frm);
		assertEquals("success", temp);
		System.out.println(frm.getOvID());
		//Remove Instruction
		frm = new EditOfficeVisitForm();
		frm.setHcpID("9000000000");
		frm.setPatientID("1");
		frm.setVisitDate("05/02/2001");
		String id = new Long(action.getInstructionsForOfficeVisit().get(0).getInstructID() ).toString();
		frm.setRemoveInstructID( id );
		temp = action.updateInformation(frm);
		assertEquals("success", temp);
	} 	
}
